#pragma once


// CVideoWindow
#include "viewsupport/DirectDrawer.h"
#include "include/frameinfo/frame.h"
#include "rfc/runnable.h"
#include "AudioLocalClient.h"
#include "bmp.h"

class CCustomWnd : public CWnd
{
	DECLARE_DYNAMIC(CCustomWnd)
public:
	CCustomWnd();
	virtual ~CCustomWnd();
	DECLARE_MESSAGE_MAP()
	afx_msg void OnPaint();
};

class CFxWindowClientView;
class CVideoWindow : public CWnd, public Runnable
{
	DECLARE_DYNAMIC(CVideoWindow)

public:
	CVideoWindow();
	virtual ~CVideoWindow();
public:
	static NVR_RAW_IMAGE*	m_nvrRawImageList[MAX_DVR_CHANNEL];
	static int*				nvrVideoListIndexs[MAX_DVR_CHANNEL];
	NVR_RAW_IMAGE*			nvrRawImage;
	static HANDLE			m_hMapFile;
	static HANDLE			m_hMapFileHeader;
	static bool				m_bfirsttime;
protected:
	CDirectDrawer dDraw;
	CBrush bkgndBrush;
	unsigned long t0;
	int					i_frames;
	int					prev_fps;
	bool				m_bCaptured;
	BYTE *				m_pCaptureBuffer;
	Frame 				m_CaptureFrame;
	BYTE *				m_pRefImage;	
	int					m_nBufferSize;
	std::string			m_bsic_string;
	BYTE *				m_pRGBBuffer;
	BOOL				m_bAVIFileEnable;
	BOOL				m_bOverlay;

	SIZE				m_szTarget;
	int					i_mystate;
	volatile bool		m_needPause;
protected:
	CStatic				m_VideoWindow;
	CStatic				m_StatusWindow;
	CString				m_strMsg;
	BOOL				m_bLbuttonPushed;
	BOOL				m_bZoomAreaDraw;
	LOGFONT				m_OSDCenterFont;
	COLORREF			m_OSDColor;
	wchar_t				wstrFontFamily[32];
	int					p_fontSizeForTextOverlay;
	wchar_t				videoName[200], recordingStatus[30], motionStatus[30], audioStatus[30], ptzStatus[30], centerStr[30], dateTimeStr[30];
protected:

	/* misc properties */
	int            i_img_width;
	int            i_img_height;
	int            i_chroma;
	bool           b_chroma; /* Force a specific chroma on the dshow input */

	__int64		   i_prev_atimestamp;
	__int64		   i_prev_vtimestamp;
	int			   videoInIndex;
	char		   videoInName[200];
	int			   videoListIndex; // video list index

protected:
	bool			b_lnNoCon;
	int				var_int_lowRes;
	char			_c_ownerStateStr[256];
	int				var_int_status;
	bool			b_lnConnecFlag;

public:
	// Properties
	//
	BOOL	m_bAudioSetting;
	BOOL    m_bPlayListNextFuncStatus; // playlistNext TRUE, else False
	int		m_kindLiveSearch;
	CString m_currentUri, m_realCurrentUri;
	CString m_strRealTextoverlay;
	BOOL    m_bEnableDigitalZoom;
	int		ownerNo;
	CFxWindowClientView *	m_wndClientView;
	// CameraInfo *ownerCameraInfo;
	int		serverID;
	int		videoIndex;
	int		cntForPlay;
	BOOL    ownerState; // TRUE : Normal, FALSE : Deleted, Error
	int		m_stopPlayPauseStatue; //0:normal, 1:stop, 2:play, 3:pause

	int		m_nNoTextOverlayForFullscreen;
	BOOL    m_bFullScreen;

	WCHAR   strNoRECEndTime[50];
	int		m_nQualityID, m_nQualityChange;
	int		m_nGetLength, m_nGetLengthTickCount;

	long	m_nLockFnCall;

	int		m_nCreateBy;
	CAudioLocalClient	m_AudioClient;
	CAudio	 *	m_pAudioPlayer;
protected:
	DECLARE_MESSAGE_MAP()
private:
	void	processStandardModeOverlay(wchar_t *inputStr);
	BOOL	GetZoomWndRect( RECT * rect );
protected:
	bool	needPause();
public:

	int InitShareMemory(  int i_index );
	void	DrawStatus();
	void DrawFrame(Frame* frame);
	void DrawVideoLoss( );
	void	DrawIcons( HDC hDC, CRect & rect );
	void	SetAspectRatio( int nMode );
	int		GetAspectRatio();
	void	OnSnapshot(char* strFilePath);

	BOOL get_Visible()
	{
		BOOL result = FALSE;
		if( this->GetSafeHwnd() == NULL )
			result = FALSE;
		else
		{
			result = this->IsWindowVisible();
		}
		return result;
	}
	void put_Visible(BOOL newValue)
	{
		if( this->GetSafeHwnd() )
		{
			this->ShowWindow( newValue ? SW_SHOW : SW_HIDE );

		}
	}
	void play();
	void pause();
	void stop();
	void run();

	BOOL get_Playing()
	{
		BOOL result = get_Length();
		return result;
	}

	float get_Position()
	{
		float result;
		return result;
	}

	void put_Position(float newValue)
	{
		int getStatus = get_Length();
	}

	void put_Time(long newValue)
	{

	}
	void shuttle(long seconds)
	{
	}
	void fullscreen()
	{
	}
	long get_Length()
	{
		//0=nothing, 1=opening,2=playing,3=buffering,4=pause,5=stopped,6=enable,7=error
		long result=0;
		m_nGetLengthTickCount = GetTickCount();
		return m_nGetLength;
	}
	void playFaster()
	{
	}
	void playSlower()
	{
	}
	long get_Volume()
	{
		long result;
		return result;
	}
	void put_Volume(long newValue);
	void toggleMute()
	{
	}
	void setVariable(LPCTSTR name, VARIANT value);
	VARIANT getVariable(LPCTSTR name);
	void addTarget(LPCTSTR uri, VARIANT options, long mode, long Position)
	{
		m_bPlayListNextFuncStatus = FALSE;
	}
	long get_PlaylistIndex()
	{
		long result;
		return result;
	}
	long get_PlaylistCount()
	{
		long result = get_Length();
		if( result == 2 || result == 3 || result == 4 )
			return 1;

		return 0;
		return result;
	}
	void playlistNext()
	{
		m_bPlayListNextFuncStatus = TRUE;
	}
	void playlistPrev()
	{
	}
	void playlistClear()
	{
	}
	CString get_VersionInfo()
	{
		CString result;

		return result;
	}
	CString get_MRL()
	{
		CString result;

		return result;
	}
	void put_MRL(LPCTSTR newValue)
	{

	}
	BOOL get_AutoPlay()
	{
		BOOL result;

		return result;
	}
	void put_AutoPlay(BOOL newValue)
	{

	}
	BOOL get_AutoLoop()
	{
		BOOL result;

		return result;
	}
	void put_AutoLoop(BOOL newValue)
	{

	}
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnPaint();
	afx_msg void OnMButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnDestroy();
};
